﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Xml.Serialization;
using System.Collections;
using System.IO;
using Editor.PageControls;
using Editor.Utilities;
using Editor.QuestionInterface;

namespace Editor.Elements
{
    [XmlInclude(typeof(PageLabel)), XmlInclude(typeof(PageImageBox)), XmlInclude(typeof(PageHideButton)),
        XmlInclude(typeof(InteractivePage))]
    public class Page : Element, ICloneable
    {
        protected List<PageControl> pageControls = new List<PageControl>();
        protected List<PageControl> dummyList = new List<PageControl>();

        public Page()
        {
        }

        public Page(SDictionary<string> dictionary)
            : base(dictionary) 
        {
        }

        public override IList ChildElements
        {
            get
            {
                return dummyList;
            }
            set
            {
                dummyList = value as List<PageControl>;
            }
        }

        public List<PageControl> Controls
        {
            get
            {
                return pageControls;
            }
            set
            {
                pageControls = value;
            }
        }

        public override Element CreateChildElement(SDictionary<string> dictionary)
        {
            return null;
        }

        public void AddPageControl(PageControl pageControl)
        {
            Controls.Add(pageControl);

            if (EditorForm.CurrentProject != null)
                EditorForm.IsSaved = false;
        }

        public void RemovePageControl(PageControl pageControl)
        {
            Controls.Remove(pageControl);
            EditorForm.IsSaved = false;
        }

        public object Clone()
        {
            Page copyPage = new Page();

            copyPage.Parent = Parent;
            
            foreach (PageControl pc in pageControls)
                copyPage.pageControls.Add(pc.Clone() as PageControl);

            foreach (string lang in EditorForm.SupportedLanguages)
            {
                if (Dictionary.ContainsLanguage(lang))
                    copyPage.Dictionary[lang] = Dictionary[lang];
            }

            return copyPage;
        }
    }
}
